
##Generate Internal Coordinate table in current CHARMM interpreter
oo::define Charmm method genIC {} {
	my sendCmd "ic generate\nic fill\n"
}
##Regenerate Internal Coordinate table in current CHARMM interpreter
oo::define Charmm method refillIC {} {
	my sendCmd "ic fill\n"
}

##Get the current IC table from the CHARMM interpreter
oo::define Charmm method getIC {} {
    set ic_table [ my sendCmd "ic print" ]
    set IC(num) {}
    set IC(resid) {}
    set IC(atom) {}
    set IC(name) {}
    set IC(Rij) {}
    set IC(Tikj) {}
    set IC(phi) {}
    set IC(Tjkl) {}
    set IC(Rkl) {}
    foreach line [split $ic_table \n] {
	if  [regexp {\d+\s+\d+\s+[A-Z]+} $line] {
	    set wlist [regexp -inline -all -- {\S+} $line]
	    lappend IC(num) [lindex $wlist 0]
	    lappend IC(resid)  [list [ lindex $wlist 1] [lindex $wlist 3] [lindex $wlist 5] [lindex $wlist 7]]
	    lappend IC(atom)  [list [ lindex $wlist 2] [lindex $wlist 4] [lindex $wlist 6] [lindex $wlist 8]]
	    lappend IC(name) [join [lrange $wlist 1 8] " "]
	    lappend IC(Rij) [lindex $wlist 9]
	    lappend IC(Tikj) [lindex $wlist 10]
	    lappend IC(phi) [lindex $wlist 11]
	    lappend IC(Tjkl) [lindex $wlist 12]
	    lappend IC(Rkl) [lindex $wlist 13]
	}
    }
    return [array get IC]
}
